package com.shujia.scala

object Demo5Class {
  def main(args: Array[String]): Unit = {

    val p = new Person("张三", 23)

    println(p)


    val stu = new Student1("王五", 24, "文科一班")


    println(stu)

  }
}


class Person(name: String, age: Int) {

  val _name: String = name
  val _age: Int = age

  override def toString: String = {

    _name + "\t" + _age
  }
}

/**
  * 继承
  * 在继承的时候需要显示指定调用父类构造函数
  *
  */

class Student1(name: String, age: Int, clazz: String) extends Person(name, age) {

  val _clazz: String = clazz

  //重写父类构造函数
  override def toString: String = {
    _name + "\t" + _age + "\t" + _clazz
  }
}


abstract class Abs() {

  //抽象方法
  def toInt(str: String): Int
}

trait Tr {

  def toDouble(str: String): Double


}


class Str extends Abs with Tr {

  //实现抽象方法
  override def toInt(str: String): Int = {

    return str.toInt
  }

  override def toDouble(str: String): Double = {
    str.toDouble
  }
}


